{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\"\"\"Basic word2vec example.\"\"\"\n",
    "\n",
    "from __future__ import absolute_import\n",
    "from __future__ import division\n",
    "from __future__ import print_function\n",
    "\n",
    "import collections\n",
    "import math\n",
    "import os\n",
    "import random\n",
    "from tempfile import gettempdir\n",
    "import zipfile\n",
    "\n",
    "import numpy as np\n",
    "from six.moves import urllib\n",
    "from six.moves import xrange  # pylint: disable=redefined-builtin\n",
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n",
    "f = open('C:\\\\Users\\\\testuser\\\\Desktop\\\\workplace\\\\machinelearning\\\\10\\\\word2vec\\\\QuanSongCi.txt','r',encoding='UTF-8')\n",
    "txt = f.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "txtlixt=list(txt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1903073"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vocabulary=txtlixt\n",
    "len(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Most common words (+UNK) [['UNK', 1196], ('。', 149620), ('\\n', 117070), ('，', 108451), ('、', 19612)]\n",
      "Sample data [1503, 1828, 2, 2, 40, 613, 47, 9, 111, 117] ['潘', '阆', '\\n', '\\n', '酒', '泉', '子', '（', '十', '之']\n"
     ]
    }
   ],
   "source": [
    "# Step 2: Build the dictionary and replace rare words with UNK token.\n",
    "vocabulary_size = 5000\n",
    "\n",
    "def build_dataset(words, n_words):\n",
    "  \"\"\"Process raw inputs into a dataset.\"\"\"\n",
    "  count = [['UNK', -1]]\n",
    "  count.extend(collections.Counter(words).most_common(n_words - 1))\n",
    "  dictionary = dict()\n",
    "  for word, _ in count:\n",
    "    dictionary[word] = len(dictionary)\n",
    "  data = list()\n",
    "  unk_count = 0\n",
    "  for word in words:\n",
    "    index = dictionary.get(word, 0)\n",
    "    if index == 0:  # dictionary['UNK']\n",
    "      unk_count += 1\n",
    "    data.append(index)\n",
    "  count[0][1] = unk_count\n",
    "  reversed_dictionary = dict(zip(dictionary.values(), dictionary.keys()))\n",
    "  return data, count, dictionary, reversed_dictionary\n",
    "\n",
    "# Filling 4 global variables:\n",
    "# data - list of codes (integers from 0 to vocabulary_size-1).\n",
    "#   This is the original text but words are replaced by their codes\n",
    "# count - map of words(strings) to count of occurrences\n",
    "# dictionary - map of words(strings) to their codes(integers)\n",
    "# reverse_dictionary - maps codes(integers) to words(strings)\n",
    "data, count, dictionary, reverse_dictionary = build_dataset(vocabulary,\n",
    "                                                            vocabulary_size)\n",
    "#del vocabulary  # Hint to reduce memory.\n",
    "print('Most common words (+UNK)', count[:5])\n",
    "print('Sample data', data[:10], [reverse_dictionary[i] for i in data[:10]])\n",
    "\n",
    "data_index = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1828 阆 -> 1503 潘\n",
      "1828 阆 -> 2 \n",
      "\n",
      "2 \n",
      " -> 1828 阆\n",
      "2 \n",
      " -> 2 \n",
      "\n",
      "2 \n",
      " -> 40 酒\n",
      "2 \n",
      " -> 2 \n",
      "\n",
      "40 酒 -> 2 \n",
      "\n",
      "40 酒 -> 613 泉\n"
     ]
    }
   ],
   "source": [
    "# Step 3: Function to generate a training batch for the skip-gram model.\n",
    "def generate_batch(batch_size, num_skips, skip_window):\n",
    "  global data_index\n",
    "  assert batch_size % num_skips == 0\n",
    "  assert num_skips <= 2 * skip_window\n",
    "  batch = np.ndarray(shape=(batch_size), dtype=np.int32)\n",
    "  labels = np.ndarray(shape=(batch_size, 1), dtype=np.int32)\n",
    "  span = 2 * skip_window + 1  # [ skip_window target skip_window ]\n",
    "  buffer = collections.deque(maxlen=span)\n",
    "  if data_index + span > len(data):\n",
    "    data_index = 0\n",
    "  buffer.extend(data[data_index:data_index + span])\n",
    "  data_index += span\n",
    "  for i in range(batch_size // num_skips):\n",
    "    context_words = [w for w in range(span) if w != skip_window]\n",
    "    words_to_use = random.sample(context_words, num_skips)\n",
    "    for j, context_word in enumerate(words_to_use):\n",
    "      batch[i * num_skips + j] = buffer[skip_window]\n",
    "      labels[i * num_skips + j, 0] = buffer[context_word]\n",
    "    if data_index == len(data):\n",
    "      buffer.extend(data[:span])\n",
    "      data_index = span\n",
    "    else:\n",
    "      buffer.append(data[data_index])\n",
    "      data_index += 1\n",
    "  # Backtrack a little bit to avoid skipping words in the end of a batch\n",
    "  data_index = (data_index + len(data) - span) % len(data)\n",
    "  return batch, labels\n",
    "\n",
    "batch, labels = generate_batch(batch_size=8, num_skips=2, skip_window=1)\n",
    "for i in range(8):\n",
    "  print(batch[i], reverse_dictionary[batch[i]],\n",
    "        '->', labels[i, 0], reverse_dictionary[labels[i, 0]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Step 4: Build and train a skip-gram model.\n",
    "\n",
    "batch_size = 128\n",
    "embedding_size = 128  # Dimension of the embedding vector.\n",
    "skip_window = 1       # How many words to consider left and right.\n",
    "num_skips = 2         # How many times to reuse an input to generate a label.\n",
    "num_sampled = 64      # Number of negative examples to sample.\n",
    "\n",
    "# We pick a random validation set to sample nearest neighbors. Here we limit the\n",
    "# validation samples to the words that have a low numeric ID, which by\n",
    "# construction are also the most frequent. These 3 variables are used only for\n",
    "# displaying model accuracy, they don't affect calculation.\n",
    "valid_size = 16     # Random set of words to evaluate similarity on.\n",
    "valid_window = 100  # Only pick dev samples in the head of the distribution.\n",
    "valid_examples = np.random.choice(valid_window, valid_size, replace=False)\n",
    "\n",
    "\n",
    "graph = tf.Graph()\n",
    "\n",
    "with graph.as_default():\n",
    "\n",
    "  # Input data.\n",
    "  train_inputs = tf.placeholder(tf.int32, shape=[batch_size])\n",
    "  train_labels = tf.placeholder(tf.int32, shape=[batch_size, 1])\n",
    "  valid_dataset = tf.constant(valid_examples, dtype=tf.int32)\n",
    "\n",
    "  # Ops and variables pinned to the CPU because of missing GPU implementation\n",
    "  with tf.device('/cpu:0'):\n",
    "    # Look up embeddings for inputs.\n",
    "    embeddings = tf.Variable(\n",
    "        tf.random_uniform([vocabulary_size, embedding_size], -1.0, 1.0))\n",
    "    embed = tf.nn.embedding_lookup(embeddings, train_inputs)\n",
    "\n",
    "    # Construct the variables for the NCE loss\n",
    "    nce_weights = tf.Variable(\n",
    "        tf.truncated_normal([vocabulary_size, embedding_size],\n",
    "                            stddev=1.0 / math.sqrt(embedding_size)))\n",
    "    nce_biases = tf.Variable(tf.zeros([vocabulary_size]))\n",
    "\n",
    "  # Compute the average NCE loss for the batch.\n",
    "  # tf.nce_loss automatically draws a new sample of the negative labels each\n",
    "  # time we evaluate the loss.\n",
    "  # Explanation of the meaning of NCE loss:\n",
    "  #   http://mccormickml.com/2016/04/19/word2vec-tutorial-the-skip-gram-model/\n",
    "  loss = tf.reduce_mean(\n",
    "      tf.nn.nce_loss(weights=nce_weights,\n",
    "                     biases=nce_biases,\n",
    "                     labels=train_labels,\n",
    "                     inputs=embed,\n",
    "                     num_sampled=num_sampled,\n",
    "                     num_classes=vocabulary_size))\n",
    "\n",
    "  # Construct the SGD optimizer using a learning rate of 1.0.\n",
    "  optimizer = tf.train.GradientDescentOptimizer(1.0).minimize(loss)\n",
    "\n",
    "  # Compute the cosine similarity between minibatch examples and all embeddings.\n",
    "  norm = tf.sqrt(tf.reduce_sum(tf.square(embeddings), 1, keep_dims=True))\n",
    "  normalized_embeddings = embeddings / norm\n",
    "  valid_embeddings = tf.nn.embedding_lookup(\n",
    "      normalized_embeddings, valid_dataset)\n",
    "  similarity = tf.matmul(\n",
    "      valid_embeddings, normalized_embeddings, transpose_b=True)\n",
    "\n",
    "  # Add variable initializer.\n",
    "  init = tf.global_variables_initializer()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Initialized\n",
      "Average loss at step  0 :  180.176513672\n",
      "Nearest to ）: 直, 娜, 插, 绎, 亘, 巡, 粮, 沆,\n",
      "Nearest to 南: 密, 莆, 锥, 匣, 蟠, 晟, 猷, 荛,\n",
      "Nearest to 山: 枧, 脐, 川, 慈, 峤, 耀, 菽, 殚,\n",
      "Nearest to 梦: 瘦, 睐, 柄, ., 启, 驻, 晃, 钧,\n",
      "Nearest to 情: 翠, 袍, ◎, 囊, 畅, 丘, 特, 聆,\n",
      "Nearest to 小: 簦, 悲, 瓞, 芗, 入, 拕, 箴, 拦,\n",
      "Nearest to 为: 荷, 匀, 瓷, 材, 韵, 洪, 毁, 砑,\n",
      "Nearest to 去: 滓, 奈, 恢, 归, 螯, 穷, 欧, 熄,\n",
      "Nearest to 飞: 谿, 飘, 泛, 莼, 幻, 罂, 翅, 惲,\n",
      "Nearest to 烟: 藏, 侥, 敌, 部, 相, 孚, 矛, 烛,\n",
      "Nearest to 明: 姑, 接, 枥, 骏, 尸, 奁, 哭, 灯,\n",
      "Nearest to 看: 逮, 乾, 绽, 佑, 蹑, 祺, 仍, 膂,\n",
      "Nearest to 东: 竦, 涸, 品, 堵, 喔, 叹, 钺, 讨,\n",
      "Nearest to 红: 甑, 锷, 舷, 踞, 槛, 龛, 涑, 鞯,\n",
      "Nearest to 处: 替, 俭, 琳, 娲, 税, 淝, 笑, 缥,\n",
      "Nearest to 醉: 恬, 镛, 拒, 摊, 竿, 讼, 析, 毯,\n",
      "Average loss at step  2000 :  21.4383253084\n",
      "Average loss at step  4000 :  5.33162984765\n",
      "Average loss at step  6000 :  4.90217872822\n",
      "Average loss at step  8000 :  4.68060826266\n",
      "Average loss at step  10000 :  4.59934254891\n",
      "Nearest to ）: 巡, 浣, 烧, 插, 粱, 。, 直, 粮,\n",
      "Nearest to 南: 密, 西, 变, 把, 蟠, 锥, 嘲, 莆,\n",
      "Nearest to 山: 耀, 奕,  , 峤, 器, 川, 拭, 脐,\n",
      "Nearest to 梦: 瘦, ., 睐, 钧, 麻, 启, 柄, 芜,\n",
      "Nearest to 情: 袍, 懒, 翠, 兔, 囊, 鞘, 特, 引,\n",
      "Nearest to 小: 悲, 芗, 蓝, 浣, 要, 脚, 护, 入,\n",
      "Nearest to 为:  , 匀, 瓷, 材, 与, 荷, 知, 韵,\n",
      "Nearest to 去: 归, 滓, 穷, 软, 崖, 奈, 醒, 螯,\n",
      "Nearest to 飞: 飘, 泛, 幻, 莼, 沈, 湿, 冷, 碧,\n",
      "Nearest to 烟: 藏, 敌, 辽, 烛, 侥, 堑, 女, 部,\n",
      "Nearest to 明: 姑, 接, 奁, 灯, 骏, 鸪, 漪, 泠,\n",
      "Nearest to 看: 乾, 绽, 道, 三, 仍, 逮, 蹑, 祺,\n",
      "Nearest to 东: 品, 砌, 苕, 讨, 墨, 叹, 忪, 堵,\n",
      "Nearest to 红: 槛, 宽, 拳, 暇, 拂, 鞯, 甑, 腔,\n",
      "Nearest to 处: 缥, 替, 常, 俭, 笑, □, 驼, 殷,\n",
      "Nearest to 醉: 摊, 篱, 湘, 恬, 拒, 甘, 鹿, 诉,\n",
      "Average loss at step  12000 :  4.56086032033\n",
      "Average loss at step  14000 :  4.4565028342\n",
      "Average loss at step  16000 :  4.46863070834\n",
      "Average loss at step  18000 :  4.49884917438\n",
      "Average loss at step  20000 :  4.44171242058\n",
      "Nearest to ）: 浣, 。, 烧, 粮, 巡, 粱, 插, ·,\n",
      "Nearest to 南: 西, 密, 锥, 变, 嘲, 荔, 蟠, 丧,\n",
      "Nearest to 山: 耀, 奕,  , 器, 拭, 峤, 喧, 旅,\n",
      "Nearest to 梦: ., 瘦, 钧, 启, 睐, 麻, 柄, 邑,\n",
      "Nearest to 情: 袍, 懒, 鞘, 兔, 囊, ◎, 翠, 特,\n",
      "Nearest to 小: 蓝, 簦, 芗, 瓞, 浣, 越, 悲, 拦,\n",
      "Nearest to 为: 与, 瓷, 匀,  , 知, 材, 砑, 洪,\n",
      "Nearest to 去: 归, 滓, 软, 崖, 螯, 讨, 醒, 穷,\n",
      "Nearest to 飞: 飘, 湿, 巘, 幻, 沈, 泼, 莼, 冷,\n",
      "Nearest to 烟: 藏, 辽, 敌, 侥, 烛, 堑, 恶, 云,\n",
      "Nearest to 明: 姑, 瘳, 接, 骏, 漪, 搴, 泠, 鸪,\n",
      "Nearest to 看: 蹑, 乾, 道, 祺, 逮, 三, 仍, 废,\n",
      "Nearest to 东: 品, 忪, 苕, 吾, 西, 甑, 讨, 抬,\n",
      "Nearest to 红: 暇, 甑, 拳, 槛, 香, 宽, 拂, 鞯,\n",
      "Nearest to 处: 俭, 淝, 警, 常, 替, 缥, 琳, 威,\n",
      "Nearest to 醉: 篱, 摊, 笑, 湘, 鹿, 甘, 拒, 镛,\n",
      "Average loss at step  22000 :  4.39206706977\n",
      "Average loss at step  24000 :  4.34762552643\n",
      "Average loss at step  26000 :  4.35366375732\n",
      "Average loss at step  28000 :  4.41146004868\n",
      "Average loss at step  30000 :  4.32350723147\n",
      "Nearest to ）: 浣, ·, 粮, 。, 之, 烧, 粱, 巡,\n",
      "Nearest to 南: 西, 密, 嘲, 荔, 变, 锥, 蟠, 丧,\n",
      "Nearest to 山: 耀, 奕, 旅, 器, 拭,  , 曳, 云,\n",
      "Nearest to 梦: ., 瘦, 钧, 睐, 启, 麻, 柄, 邑,\n",
      "Nearest to 情: 袍, 鞘, ◎, 懒, 兔, 囊, 特, 处,\n",
      "Nearest to 小: 蓝, 簦, 越, 芗, 瓞, 贷, 浣, 畔,\n",
      "Nearest to 为: 与,  , 材, 知, 匀, 瓷, 洪, 妇,\n",
      "Nearest to 去: 归, 滓, 软, 崖, 来, 昊, 讨, 别,\n",
      "Nearest to 飞: 飘, 湿, 巘, 幻, 泼, 沈, 冷, 谿,\n",
      "Nearest to 烟: 辽, 侥, 藏, 敌, 堑, 恶, 云, 烛,\n",
      "Nearest to 明: 姑, 瘳, 搴, 漪, 骏, 接, 灯, 泠,\n",
      "Nearest to 看: 见, 祺, 愠, 细, 浙, 三, 废, 仍,\n",
      "Nearest to 东: 西, 品, 吾, 忪, 苕, 甑, 讨, 飒,\n",
      "Nearest to 红: 暇, 甑, 槛, 拳, 喔, 香, 暖, 鞯,\n",
      "Nearest to 处: 俭, 常, 淝, 警, 琳, 震, 蘩, 又,\n",
      "Nearest to 醉: 笑, 篱, 摊, 镛, 甘, 鹿, 湘, 恬,\n",
      "Average loss at step  32000 :  4.16483570385\n",
      "Average loss at step  34000 :  4.20347704995\n",
      "Average loss at step  36000 :  4.23007381165\n",
      "Average loss at step  38000 :  4.19313079059\n",
      "Average loss at step  40000 :  4.18030089706\n",
      "Nearest to ）: ·, 浣, 。, 粮, 之, 巳, 粱, 芰,\n",
      "Nearest to 南: 西, 荔, 密, 嘲, 头, 锥, 丧, 蓓,\n",
      "Nearest to 山: 耀, 奕, 旅, 器, 拭, 殚, 区, 堵,\n",
      "Nearest to 梦: ., 瘦, 钧, 睐, 瞒, 这, 麻, 邑,\n",
      "Nearest to 情: ◎, 鞘, 懒, 袍, 砑, 兔, 感, 处,\n",
      "Nearest to 小: 蓝, 簦, 浣, 越, 瓞, 仄, 芗, 脚,\n",
      "Nearest to 为: 与, 瓷, 匀, 知,  , 材, 怕, 续,\n",
      "Nearest to 去: 归, 滓, 软, 来, 崖, 昊, 讨, 醒,\n",
      "Nearest to 飞: 飘, 湿, 巘, 泼, 幻, 惲, 冷, 脂,\n",
      "Nearest to 烟: 辽, 云, 藏, 侥, 恶, 敌, 堑, 雾,\n",
      "Nearest to 明: 搴, 漪, 瘳, 姑, 灯, 骏, 泠, 接,\n",
      "Nearest to 看: 见, 祺, 愠, 向, 乏, 共, 仔, 仍,\n",
      "Nearest to 东: 西, 吾, 品, 北, 苕, 飒, 忪, 吼,\n",
      "Nearest to 红: 暇, 甑, 槛, 拳, 喔, 暖, 拂, 囗,\n",
      "Nearest to 处: 俭, 淝, 常, 警, 琳, 情, 蘩, 威,\n",
      "Nearest to 醉: 笑, 篱, 鹿, 甘, 镛, 摊, 湘, 拒,\n",
      "Average loss at step  42000 :  4.21350813568\n",
      "Average loss at step  44000 :  4.19945631909\n",
      "Average loss at step  46000 :  4.23664659023\n",
      "Average loss at step  48000 :  4.28152656841\n",
      "Average loss at step  50000 :  4.26149325848\n",
      "Nearest to ）: 。, 浣, ·, 粮, 祁, 巳, 员, 贺,\n",
      "Nearest to 南: 西, 荔, 嘲, 密, 头, 丧, 锥, 湖,\n",
      "Nearest to 山: 耀, 峰, 旅, 奕, 殚, 堵, 区, 河,\n",
      "Nearest to 梦: ., 瞒, 钧, 瘦, 这, 邑, 睐, 忌,\n",
      "Nearest to 情: 懒, 鞘, 袍, ◎, 囗, 砑, 愁, 主,\n",
      "Nearest to 小: 蓝, 越, 贷, 簦, 瓞, 傍, 畔, 浣,\n",
      "Nearest to 为: 与, 瓷, 知, 似, 问, 匀, 洪,  ,\n",
      "Nearest to 去: 归, 软, 来, 滓, 昊, 讨, 崖, 向,\n",
      "Nearest to 飞: 湿, 飘, 巘, 泼, 幻, 谿, 冷, 颇,\n",
      "Nearest to 烟: 辽, 云, 恶, 侥, 堑, 藏, 雾, 敌,\n",
      "Nearest to 明: 瘳, 搴, 漪, 姑, 接, 泠, 骏, 某,\n",
      "Nearest to 看: 见, 向, 仔, 烂, 愠, 浙, 祺, 听,\n",
      "Nearest to 东: 西, 北, 吾, 品, 飒, 吼, 苕, 甑,\n",
      "Nearest to 红: 暇, 甑, 囗, 拳, 喔, 槛, 香, 厕,\n",
      "Nearest to 处: 淝, 俭, 警, 常, 情, 又, 蘩, 尼,\n",
      "Nearest to 醉: 笑, 篱, 鹿, 甘, 镛, 摊, 嫌, 挈,\n",
      "Average loss at step  52000 :  4.24157875037\n",
      "Average loss at step  54000 :  4.19384654748\n",
      "Average loss at step  56000 :  4.23376289213\n",
      "Average loss at step  58000 :  4.24963338149\n",
      "Average loss at step  60000 :  4.17677017856\n",
      "Nearest to ）: ·, 之, 粮, 浣, 。, 员, 吕, \n",
      ",\n",
      "Nearest to 南: 西, 荔, 嘲, 琢, 头, 密, 怃, 屃,\n",
      "Nearest to 山: 峰, 耀, 旅, 禽, 奕, 河, 堵, 殚,\n",
      "Nearest to 梦: ., 这, 瞒, 钧, 瘦, 邑, 颇, 暑,\n",
      "Nearest to 情: 鞘, 懒, 袍, ◎, 愁, 恙, 砑, 囗,\n",
      "Nearest to 小: 蓝, 畔, 越, 簦, 瓞, 贷, 傍, 柯,\n",
      "Nearest to 为: 与, 问, 知, 似, 瓷, 续, 匀, 材,\n",
      "Nearest to 去: 归, 来, 昊, 滓, 软, 别, 向, 讨,\n",
      "Nearest to 飞: 湿, 飘, 巘, 颇, 泼, 幻, 芦, 脂,\n",
      "Nearest to 烟: 辽, 雾, 云, 恶, 堑, 侥, 藏, 敌,\n",
      "Nearest to 明: 搴, 瘳, 漪, 姑, 接, 衿, 骏, 奁,\n",
      "Nearest to 看: 见, 向, 仔, 烂, 愠, 听, 垩, 伴,\n",
      "Nearest to 东: 西, 北, 吾, 品, 飒, 淮, 诘, 捺,\n",
      "Nearest to 红: 暇, 甑, 槛, 喔, 拳, 囗, 厕, 钚,\n",
      "Nearest to 处: 淝, 常, 俭, 警, 蘩, 意, 又, 情,\n",
      "Nearest to 醉: 笑, 篱, 镛, 鹿, 甘, 嫌, 摊, 救,\n",
      "Average loss at step  62000 :  4.10023353457\n",
      "Average loss at step  64000 :  4.11261343801\n",
      "Average loss at step  66000 :  4.13122552288\n",
      "Average loss at step  68000 :  4.10996481931\n",
      "Average loss at step  70000 :  4.11554892528\n",
      "Nearest to ）: ·, 。, 粮, 浣, 之, 巳, 员, 祁,\n",
      "Nearest to 南: 西, 荔, □, 头, 嘲, 屃, 琢, 密,\n",
      "Nearest to 山: 峰, 耀, 殚, 旅, 堵, 禽, 区, 护,\n",
      "Nearest to 梦: ., 这, 瞒, 钧, 邑, 忌, 瘦, 暑,\n",
      "Nearest to 情: 鞘, 懒, ◎, 袍, 愁, 感, 主, 砑,\n",
      "Nearest to 小: 蓝, □, 卢, 簦, 畔, 越, 浣, 仄,\n",
      "Nearest to 为: 与, 似, 瓷, 问, 续, 庄, 怕, 借,\n",
      "Nearest to 去: 归, 来, 昊, 滓, 讨, 向, 骑, 软,\n",
      "Nearest to 飞: 飘, 湿, 巘, 泼, 颇, 幻, 芦, 惲,\n",
      "Nearest to 烟: 雾, 云, 辽, □, 恶, 堑, 侥, 藏,\n",
      "Nearest to 明: 搴, 瘳, 漪, □, 接, 姑, 净, 娄,\n",
      "Nearest to 看: 仔, 向, □, 见, 垩, 听, 烂, 乏,\n",
      "Nearest to 东: 西, 北, 吾, □, 吼, 品, 飒, 捺,\n",
      "Nearest to 红: 暇, 甑, □, 喔, 钚, 暖, 拳, 槛,\n",
      "Nearest to 处: □, 常, 淝, 警, 俭, 意, 尼, 谬,\n",
      "Nearest to 醉: 笑, 篱, □, 嫌, 鹿, 镛, 甘, 救,\n",
      "Average loss at step  72000 :  4.12791649282\n",
      "Average loss at step  74000 :  4.12946031404\n",
      "Average loss at step  76000 :  4.19142549586\n",
      "Average loss at step  78000 :  4.19619991493\n",
      "Average loss at step  80000 :  4.1936125561\n",
      "Nearest to ）: 。, ·, 粮, 浣, 祁, 员, 菩, 芍,\n",
      "Nearest to 南: 西, 荔, 嘲, 头, 怃, 北, 层, 丧,\n",
      "Nearest to 山: 峰, 耀, 旅, 殚, 禽, 堵, 奕, 河,\n",
      "Nearest to 梦: ., 这, 瞒, 钧, 邑, 颇, 忌, 响,\n",
      "Nearest to 情: 鞘, 懒, 愁, 袍, ◎, 朋, 主, 恙,\n",
      "Nearest to 小: 蓝, 傍, 畔, 越, 贷, 卢, 鞋, 柯,\n",
      "Nearest to 为: 与, 似, 问, 瓷, 知, 借, 庄, 怕,\n",
      "Nearest to 去: 归, 来, 昊, 软, 讨, 滓, 向, 幺,\n",
      "Nearest to 飞: 飘, 湿, 巘, 芦, 颇, 泼, 谿, 赌,\n",
      "Nearest to 烟: 雾, 辽, 云, 恶, 堑, 侥, 砥, 藏,\n",
      "Nearest to 明: 瘳, 搴, 漪, 接, 姑, 娄, 衿, 净,\n",
      "Nearest to 看: 向, 仔, 听, 烂, 垩, 见, 伴, 乏,\n",
      "Nearest to 东: 西, 北, 吾, 吼, 捺, 罡, 飒, 诘,\n",
      "Nearest to 红: 暇, 甑, 囗, 喔, 厕, 钚, 拳, 菁,\n",
      "Nearest to 处: 淝, 常, 警, 俭, 意, 尼, 又, 懒,\n",
      "Nearest to 醉: 笑, 篱, 鹿, 嫌, 镛, 醒, 挈, 甘,\n",
      "Average loss at step  82000 :  4.17107852435\n",
      "Average loss at step  84000 :  4.13891463435\n",
      "Average loss at step  86000 :  4.18445650184\n",
      "Average loss at step  88000 :  4.17575154555\n",
      "Average loss at step  90000 :  4.09996457112\n",
      "Nearest to ）: ·, 之, 。, 粮, 浣, 吕, 员, 祁,\n",
      "Nearest to 南: 西, 荔, 怃, 嘲, 琢, 头, 北, 屃,\n",
      "Nearest to 山: 峰, 耀, 旅, 禽, 鼐, 护, 殚, 堵,\n",
      "Nearest to 梦: ., 这, 瞒, 邑, 钧, 事, 颇, 话,\n",
      "Nearest to 情: 鞘, 愁, 袍, 恨, ◎, 懒, 意, 恙,\n",
      "Nearest to 小: 蓝, 畔, 傍, 越, 椠, 画, 鞋, 柯,\n",
      "Nearest to 为: 与, 似, 问, 知, 借, 续, 庄, 向,\n",
      "Nearest to 去: 归, 来, 昊, 幺, 暮, 滓, 别, 欤,\n",
      "Nearest to 飞: 飘, 湿, 巘, 颇, 芦, 归, 翩, 泼,\n",
      "Nearest to 烟: 雾, 辽, 云, 恶, 堑, 抗, 梢, 砥,\n",
      "Nearest to 明: 搴, 瘳, 漪, 衿, 接, 姮, 当, 肾,\n",
      "Nearest to 看: 向, 听, 仔, 见, 烂, 垩, 伴, 扪,\n",
      "Nearest to 东: 西, 北, 罡, 飒, 吾, 吼, 诘, 捺,\n",
      "Nearest to 红: 暇, 甑, 钚, 厕, 菁, 槛, 囗, 喔,\n",
      "Nearest to 处: 常, 淝, 意, 警, 俭, □, 懒, 尼,\n",
      "Nearest to 醉: 笑, 篱, 嫌, 醒, 鹿, 镛, 析, 救,\n",
      "Average loss at step  92000 :  4.04887148213\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average loss at step  94000 :  4.08559704578\n",
      "Average loss at step  96000 :  4.05391371286\n",
      "Average loss at step  98000 :  4.07936836839\n",
      "Average loss at step  100000 :  4.05976054251\n",
      "Nearest to ）: ·, 之, 粮, 。, 祁, 浣, 傅, 巳,\n",
      "Nearest to 南: 西, 荔, 头, 怃, 北, 屃, 嘲, 薜,\n",
      "Nearest to 山: 峰, 耀, 殚, 堵, 护, 旅, 酿, 珰,\n",
      "Nearest to 梦: ., 这, 瞒, 钧, 邑, 话, 恨, 忌,\n",
      "Nearest to 情: 鞘, 愁, ◎, 懒, 恨, 感, 意, 拏,\n",
      "Nearest to 小: 蓝, 卢, 畔, 傍, 何, 柯, 椠, 越,\n",
      "Nearest to 为: 与, 似, 借, 问, 瓷, 庄, 向, 续,\n",
      "Nearest to 去: 归, 来, 昊, 幺, 讨, 骑, 向, 欤,\n",
      "Nearest to 飞: 飘, 湿, 巘, 颇, 钗, 芦, 翩, 赌,\n",
      "Nearest to 烟: 雾, 云, 辽, 恶, 堑, 绥, 砥, 暝,\n",
      "Nearest to 明: 搴, 漪, 瘳, 当, 净, 今, 姮, 十,\n",
      "Nearest to 看: 仔, 向, 垩, 听, 烂, 伴, 见, 扪,\n",
      "Nearest to 东: 西, 北, 吾, 罡, 吼, 捺, 南, 飒,\n",
      "Nearest to 红: 暇, 甑, 钚, 厕, 喔, 眇, 菁, 垢,\n",
      "Nearest to 处: 常, 淝, 意, 警, 福, 尼, 谬, 懒,\n",
      "Nearest to 醉: 笑, 篱, 嫌, 醒, 鹿, 救, 挈, 糜,\n",
      "Average loss at step  102000 :  4.07875332844\n",
      "Average loss at step  104000 :  4.0936130271\n",
      "Average loss at step  106000 :  4.14530560446\n",
      "Average loss at step  108000 :  4.14597269988\n",
      "Average loss at step  110000 :  4.17074035239\n",
      "Nearest to ）: 。, ·, 祁, 浣, 粮, 菩, 员, 之,\n",
      "Nearest to 南: 西, 荔, 北, 怃, 嘲, 层, 屃, 薜,\n",
      "Nearest to 山: 峰, 耀, 殚, 旅, 枪, 堵, 濑, 郊,\n",
      "Nearest to 梦: ., 这, 瞒, 话, 恨, 钧, 忌, 邑,\n",
      "Nearest to 情: 鞘, 愁, 懒, 恨, 拏, 意, 朋, ◎,\n",
      "Nearest to 小: 蓝, 傍, 畔, 何, 柯, 越, 卢, 贷,\n",
      "Nearest to 为: 与, 似, 问, 借, 瓷, 庄, 知, 谢,\n",
      "Nearest to 去: 归, 来, 昊, 幺, 暮, 讨, 软, 欤,\n",
      "Nearest to 飞: 飘, 湿, 巘, 芦, 翩, 颇, 谿, 钗,\n",
      "Nearest to 烟: 雾, 云, 辽, 恶, 堑, 逗, 暝, 侥,\n",
      "Nearest to 明: 瘳, 搴, 漪, 当, 姮, 今, 华, 娄,\n",
      "Nearest to 看: 向, 听, 仔, 垩, 烂, 伴, 扪, 见,\n",
      "Nearest to 东: 西, 北, 罡, 吼, 吾, 南, 迅, 诘,\n",
      "Nearest to 红: 暇, 甑, 菁, 厕, 钚, 喔, 囗, 宕,\n",
      "Nearest to 处: 淝, 意, 常, 警, 尼, 福, 懒, 谬,\n",
      "Nearest to 醉: 笑, 篱, 嫌, 醒, 鹿, 糜, 挈, 你,\n",
      "Average loss at step  112000 :  4.11250859654\n",
      "Average loss at step  114000 :  4.10309611738\n",
      "Average loss at step  116000 :  4.14733464873\n",
      "Average loss at step  118000 :  4.13918282247\n",
      "Average loss at step  120000 :  4.02903386915\n",
      "Nearest to ）: ·, 之, 粮, 吕, 祁, 员, 浣, 芍,\n",
      "Nearest to 南: 西, 荔, 北, 怃, 嘲, 屃, 蓠, 东,\n",
      "Nearest to 山: 峰, 耀, 楼, 枧, 旅, 鼐, 堵, 禽,\n",
      "Nearest to 梦: ., 这, 恨, 瞒, 事, 话, 颇, 钧,\n",
      "Nearest to 情: 愁, 鞘, 恨, 意, 拏, 恙, 心, 感,\n",
      "Nearest to 小: 蓝, 畔, 傍, 椠, 画, 何, 柯, 越,\n",
      "Nearest to 为: 与, 似, 问, 借, 共, 庄, 向, 知,\n",
      "Nearest to 去: 归, 来, 昊, 幺, 暮, 别, 欤, 滓,\n",
      "Nearest to 飞: 飘, 湿, 巘, 芦, 颇, 归, 翩, 随,\n",
      "Nearest to 烟: 雾, 云, 辽, 逗, 恶, 抗, 绥, 堑,\n",
      "Nearest to 明: 漪, 搴, 瘳, 姮, 当, 华, 衿, 十,\n",
      "Nearest to 看: 向, 听, 仔, 烂, 垩, 见, 扪, 伴,\n",
      "Nearest to 东: 西, 北, 罡, 南, 飒, 诘, 吼, 捺,\n",
      "Nearest to 红: 暇, 甑, 钚, 厕, 菁, 眇, 岖, 喔,\n",
      "Nearest to 处: 常, 意, 淝, 警, 福, 尼, 懒, 谬,\n",
      "Nearest to 醉: 笑, 醒, 篱, 嫌, 救, 糜, 析, 岖,\n",
      "Average loss at step  122000 :  4.03341559362\n",
      "Average loss at step  124000 :  4.06153649187\n",
      "Average loss at step  126000 :  4.00235526359\n",
      "Average loss at step  128000 :  4.04152285635\n",
      "Average loss at step  130000 :  4.04704031432\n",
      "Nearest to ）: ·, 之, 。, 祁, 粮, 芰, 词, 浣,\n",
      "Nearest to 南: 西, 荔, 北, 怃, 蓠, 屃, 头, 东,\n",
      "Nearest to 山: 峰, 殚, 堵, 耀, 珰, 濑, 护, 酿,\n",
      "Nearest to 梦: ., 这, 瞒, 恨, 话, 钧, 事, 邑,\n",
      "Nearest to 情: 愁, 恨, 拏, 鞘, 意, 感, 恙, ◎,\n",
      "Nearest to 小: 蓝, 卢, □, 傍, 何, 柯, 畔, 椠,\n",
      "Nearest to 为: 与, 似, 借, 问, 瓷, 庄, 向, □,\n",
      "Nearest to 去: 归, 来, 昊, 幺, 欤, 暮, 讨, 骑,\n",
      "Nearest to 飞: 飘, 翩, 钗, 湿, 巘, 芦, 颇, 幻,\n",
      "Nearest to 烟: 雾, 云, 辽, 暝, 逗, 绥, 恶, 砥,\n",
      "Nearest to 明: 搴, 瘳, 漪, 当, 姮, 十, 净, 今,\n",
      "Nearest to 看: 仔, 向, 垩, 听, 烂, 扪, 伴, □,\n",
      "Nearest to 东: 西, 北, 罡, 南, □, 吼, 迅, 捺,\n",
      "Nearest to 红: 暇, 甑, 钚, 厕, □, 菁, 眇, 垢,\n",
      "Nearest to 处: 常, □, 意, 淝, 警, 福, 尼, 谬,\n",
      "Nearest to 醉: 笑, 篱, 嫌, 醒, □, 糜, 岖, 妨,\n",
      "Average loss at step  132000 :  4.03955928373\n",
      "Average loss at step  134000 :  4.06510569823\n",
      "Average loss at step  136000 :  4.1172163012\n",
      "Average loss at step  138000 :  4.11148583341\n",
      "Average loss at step  140000 :  4.13823796523\n",
      "Nearest to ）: ·, 。, 祁, 粮, 芍, 贺, 盎, 浣,\n",
      "Nearest to 南: 西, 北, 荔, 怃, 东, 嘲, 屃, 薜,\n",
      "Nearest to 山: 峰, 耀, 殚, 旅, 枪, 濑, 枧, 堵,\n",
      "Nearest to 梦: ., 这, 恨, 瞒, 话, 椠, 魂, 忌,\n",
      "Nearest to 情: 愁, 鞘, 恨, 拏, 意, 恙, 朋, 感,\n",
      "Nearest to 小: 蓝, 傍, 畔, 何, 柯, 椠, 卢, 贷,\n",
      "Nearest to 为: 与, 似, 问, 借, 庄, 共, 瓷, 同,\n",
      "Nearest to 去: 归, 来, 昊, 幺, 暮, 讨, 欤, 骑,\n",
      "Nearest to 飞: 飘, 翩, 芦, 钗, 巘, 凋, 湿, 谿,\n",
      "Nearest to 烟: 雾, 云, 辽, 逗, 暝, 恶, 堑, 浸,\n",
      "Nearest to 明: 瘳, 搴, 漪, 姮, 当, 华, 净, 衿,\n",
      "Nearest to 看: 听, 向, 仔, 垩, 烂, 伴, 对, 起,\n",
      "Nearest to 东: 西, 北, 南, 罡, 迅, 吼, 斜, 飒,\n",
      "Nearest to 红: 暇, 甑, 钚, 菁, 厕, 垢, 喔, 拳,\n",
      "Nearest to 处: 意, 淝, 常, 福, 警, 尼, 懒, 慕,\n",
      "Nearest to 醉: 笑, 醒, 嫌, 篱, 糜, 岖, 逡, 析,\n",
      "Average loss at step  142000 :  4.09621375537\n",
      "Average loss at step  144000 :  4.07065841305\n",
      "Average loss at step  146000 :  4.12448349285\n",
      "Average loss at step  148000 :  4.10555126476\n",
      "Average loss at step  150000 :  3.98674922359\n",
      "Nearest to ）: ·, 之, 吕, 祁, 粮, 。, 员, 芍,\n",
      "Nearest to 南: 西, 北, 荔, 怃, 东, 蓠, 屃, 嘲,\n",
      "Nearest to 山: 峰, 岫, 楼, 枧, 耀, 旅, 濑, 堵,\n",
      "Nearest to 梦: ., 这, 恨, 话, 事, 瞒, 椠, 魂,\n",
      "Nearest to 情: 愁, 恨, 鞘, 意, 拏, 恙, 心, 感,\n",
      "Nearest to 小: 蓝, 畔, 傍, 椠, 画, 柯, 移, 卢,\n",
      "Nearest to 为: 与, 似, 问, 借, 同, 共, 庄, 向,\n",
      "Nearest to 去: 归, 来, 幺, 昊, 暮, 欤, 别, 稳,\n",
      "Nearest to 飞: 飘, 翩, 芦, 颇, 巘, 湿, 钗, 随,\n",
      "Nearest to 烟: 雾, 云, 辽, 逗, 暝, 绥, 抗, 霭,\n",
      "Nearest to 明: 漪, 搴, 瘳, 当, 姮, 衿, 华, 十,\n",
      "Nearest to 看: 听, 向, 仔, 烂, 垩, 扪, 伴, 起,\n",
      "Nearest to 东: 西, 北, 南, 罡, 飒, 诘, 捺, 吼,\n",
      "Nearest to 红: 暇, 甑, 钚, 菁, 花, 厕, 眇, 拳,\n",
      "Nearest to 处: 意, 常, 淝, 警, 福, 尼, 懒, 鞬,\n",
      "Nearest to 醉: 笑, 醒, 嫌, 岖, 糜, 篱, 析, 救,\n",
      "Average loss at step  152000 :  4.01143490732\n",
      "Average loss at step  154000 :  4.03964258993\n",
      "Average loss at step  156000 :  3.98354644668\n",
      "Average loss at step  158000 :  4.02203547025\n",
      "Average loss at step  160000 :  4.0213225565\n",
      "Nearest to ）: ·, 。, 祁, 之, 粮, 盎, 芰, 芍,\n",
      "Nearest to 南: 西, 北, 荔, 东, 怃, 头, 蓠, 屃,\n",
      "Nearest to 山: 峰, 水, 岫, 濑, 殚, 岩, 珰, 枧,\n",
      "Nearest to 梦: ., 这, 恨, 话, 瞒, 魂, 椠, 钧,\n",
      "Nearest to 情: 愁, 拏, 恨, 鞘, 意, 感, 恙, ◎,\n",
      "Nearest to 小: 蓝, 卢, 椠, 傍, 畔, 柯, 贪, 移,\n",
      "Nearest to 为: 与, 似, 借, 庄, 向, 问, 共, 瓷,\n",
      "Nearest to 去: 归, 来, 昊, 幺, 欤, 暮, 骑, 讨,\n",
      "Nearest to 飞: 飘, 翩, 钗, 芦, 凋, 谿, 巘, 幻,\n",
      "Nearest to 烟: 雾, 暝, 辽, 云, 逗, 绥, 霭, 蒿,\n",
      "Nearest to 明: 搴, 漪, 瘳, 姮, 当, 十, 净, 圆,\n",
      "Nearest to 看: 仔, 听, 垩, 向, 扪, 起, 烂, 伴,\n",
      "Nearest to 东: 西, 北, 南, 罡, 迅, 斜, 吼, 捺,\n",
      "Nearest to 红: 暇, 甑, 钚, 厕, 菁, 花, 垢, 眇,\n",
      "Nearest to 处: 意, 常, 淝, 福, 警, 便, 尼, 驶,\n",
      "Nearest to 醉: 笑, 嫌, 醒, 篱, 岖, 糜, 妨, 鲊,\n",
      "Average loss at step  162000 :  4.00695559919\n",
      "Average loss at step  164000 :  4.05037862432\n",
      "Average loss at step  166000 :  4.08204148161\n",
      "Average loss at step  168000 :  4.08399104106\n",
      "Average loss at step  170000 :  4.10292973733\n",
      "Nearest to ）: 。, ·, 祁, 粮, 芍, 盎, 贺, 浣,\n",
      "Nearest to 南: 西, 北, 荔, 东, 怃, 蓠, 屃, 层,\n",
      "Nearest to 山: 峰, 岫, 枧, 岩, 枪, 殚, 濑, 水,\n",
      "Nearest to 梦: 恨, ., 这, 魂, 话, 椠, 瞒, 忌,\n",
      "Nearest to 情: 愁, 恨, 拏, 意, 鞘, 恙, 黯, 绪,\n",
      "Nearest to 小: 蓝, 傍, 畔, 移, 椠, 柯, 集, 画,\n",
      "Nearest to 为: 与, 似, 借, 问, 共, 同, 庄, 如,\n",
      "Nearest to 去: 归, 来, 昊, 幺, 暮, 欤, 讨, 却,\n",
      "Nearest to 飞: 飘, 翩, 钗, 芦, 凋, 巘, 谿, 湿,\n",
      "Nearest to 烟: 雾, 暝, 云, 辽, 逗, 霭, 荫, 恶,\n",
      "Nearest to 明: 瘳, 搴, 姮, 当, 漪, 华, 圆, 缺,\n",
      "Nearest to 看: 听, 向, 仔, 垩, 烂, 对, 扪, 起,\n",
      "Nearest to 东: 西, 北, 南, 迅, 斜, 罡, 诘, 甑,\n",
      "Nearest to 红: 甑, 暇, 钚, 菁, 厕, 垢, 拳, 宕,\n",
      "Nearest to 处: 意, 淝, 福, 常, 警, 便, 慕, 尼,\n",
      "Nearest to 醉: 笑, 醒, 嫌, 岖, 糜, 逡, 睡, 你,\n",
      "Average loss at step  172000 :  4.08407253909\n",
      "Average loss at step  174000 :  4.04994993663\n",
      "Average loss at step  176000 :  4.10514349163\n",
      "Average loss at step  178000 :  4.08119865358\n",
      "Average loss at step  180000 :  3.94785681117\n",
      "Nearest to ）: ·, 之, 祁, 吕, 粮, 。, 芍, 员,\n",
      "Nearest to 南: 西, 北, 荔, 怃, 东, 蓠, 头, 屃,\n",
      "Nearest to 山: 峰, 岫, 楼, 岩, 水, 枧, 濑, 莆,\n",
      "Nearest to 梦: 恨, 这, ., 事, 魂, 话, 椠, 瞒,\n",
      "Nearest to 情: 愁, 恨, 拏, 意, 恙, 鞘, 心, 感,\n",
      "Nearest to 小: 蓝, 傍, 椠, 移, 畔, 画, 绣, 扁,\n",
      "Nearest to 为: 与, 似, 同, 问, 共, 借, 庄, 向,\n",
      "Nearest to 去: 归, 来, 幺, 昊, 暮, 欤, 却, 别,\n",
      "Nearest to 飞: 飘, 翩, 芦, 钗, 随, 巘, 颇, 湿,\n",
      "Nearest to 烟: 雾, 逗, 辽, 云, 暝, 霭, 绥, 荫,\n",
      "Nearest to 明: 瘳, 搴, 漪, 姮, 当, 光, 衿, 圆,\n",
      "Nearest to 看: 听, 向, 仔, 扪, 问, 垩, 起, 烂,\n",
      "Nearest to 东: 西, 北, 南, 罡, 斜, 迅, 飒, 诘,\n",
      "Nearest to 红: 暇, 甑, 钚, 菁, 宕, 眇, 花, 厕,\n",
      "Nearest to 处: 意, 淝, 警, 常, 福, 便, 时, 鞬,\n",
      "Nearest to 醉: 笑, 醒, 岖, 糜, 嫌, 析, 妨, 逡,\n",
      "Average loss at step  182000 :  4.00548522961\n",
      "Average loss at step  184000 :  4.02188896286\n",
      "Average loss at step  186000 :  3.95909575677\n",
      "Average loss at step  188000 :  4.00215579426\n",
      "Average loss at step  190000 :  4.0075367628\n",
      "Nearest to ）: ·, 。, 祁, 之, 词, 芍, 盎, 芰,\n",
      "Nearest to 南: 西, 北, 荔, 东, 怃, 蓠, 头, 屃,\n",
      "Nearest to 山: 峰, 岫, 水, 岩, 珰, 濑, 枧, 楼,\n",
      "Nearest to 梦: ., 这, 恨, 魂, 话, 椠, 瞒, 苕,\n",
      "Nearest to 情: 拏, 愁, 恨, 意, 恙, 感, 鞘, 怨,\n",
      "Nearest to 小: 蓝, 移, 卢, 椠, 傍, 贪, 柯, 瓞,\n",
      "Nearest to 为: 与, 似, 借, 庄, 同, 向, 共, 瓷,\n",
      "Nearest to 去: 归, 来, 幺, 昊, 欤, 暮, 却, 骑,\n",
      "Nearest to 飞: 飘, 翩, 钗, 凋, 谿, 鹳, 幻, 芦,\n",
      "Nearest to 烟: 雾, 云, 辽, 暝, 逗, 霭, 绥, 蒿,\n",
      "Nearest to 明: 搴, 瘳, 当, 姮, 漪, 圆, 衿, 十,\n",
      "Nearest to 看: 听, 仔, 垩, 向, 问, 起, 扪, 烂,\n",
      "Nearest to 东: 西, 北, 南, 斜, 罡, 迅, 甑, 吼,\n",
      "Nearest to 红: 暇, 钚, 甑, 菁, 厕, 垢, 嘘, 骎,\n",
      "Nearest to 处: 意, 常, 福, 便, 警, 淝, 更, 时,\n",
      "Nearest to 醉: 笑, 醒, 嫌, 岖, 糜, 妨, 你, 鲊,\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average loss at step  192000 :  4.00345015216\n",
      "Average loss at step  194000 :  4.02641116369\n",
      "Average loss at step  196000 :  4.06986441398\n",
      "Average loss at step  198000 :  4.06756875062\n",
      "Average loss at step  200000 :  4.08700306678\n",
      "Nearest to ）: ·, 。, 祁, 芍, 粮, 之, 盎, 鹈,\n",
      "Nearest to 南: 西, 北, 荔, 怃, 东, 蓠, 屃, 层,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 殚, 濑, 枪, 瑁,\n",
      "Nearest to 梦: 恨, ., 魂, 这, 话, 椠, 瞒, 忌,\n",
      "Nearest to 情: 愁, 恨, 拏, 意, 恙, 怨, 鞘, 绪,\n",
      "Nearest to 小: 蓝, 傍, 移, 畔, 柯, 贷, 集, 好,\n",
      "Nearest to 为: 与, 似, 共, 同, 借, 庄, 问, 伴,\n",
      "Nearest to 去: 归, 来, 幺, 昊, 暮, 欤, 却, 赣,\n",
      "Nearest to 飞: 飘, 翩, 钗, 芦, 凋, 谿, 吹, 巘,\n",
      "Nearest to 烟: 雾, 逗, 暝, 云, 辽, 霭, 绥, 荫,\n",
      "Nearest to 明: 瘳, 当, 姮, 搴, 华, 缺, 圆, 漪,\n",
      "Nearest to 看: 听, 向, 仔, 垩, 对, 起, 问, 说,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 罡, 诘, 甑,\n",
      "Nearest to 红: 甑, 暇, 菁, 钚, 垢, 厕, 宕, 拳,\n",
      "Nearest to 处: 意, 便, 淝, 警, 福, 常, 更, 句,\n",
      "Nearest to 醉: 笑, 醒, 嫌, 岖, 逡, 糜, 睡, 你,\n",
      "Average loss at step  202000 :  4.06100180697\n",
      "Average loss at step  204000 :  4.03309349716\n",
      "Average loss at step  206000 :  4.09036066163\n",
      "Average loss at step  208000 :  4.05610761583\n",
      "Average loss at step  210000 :  3.93131954479\n",
      "Nearest to ）: ·, 祁, 吕, 之, 粮, 芍, 。, 盎,\n",
      "Nearest to 南: 西, 北, 荔, 怃, 东, 蓠, 屃, 闽,\n",
      "Nearest to 山: 峰, 岫, 岩, 楼, 枧, 濑, 水, 莆,\n",
      "Nearest to 梦: 恨, ., 这, 魂, 话, 椠, 事, 瞒,\n",
      "Nearest to 情: 愁, 恨, 拏, 意, 恙, 感, 怨, 鞘,\n",
      "Nearest to 小: 蓝, 移, 椠, 画, 傍, 畔, 卢, 好,\n",
      "Nearest to 为: 与, 似, 同, 共, 借, 庄, 问, 向,\n",
      "Nearest to 去: 归, 来, 幺, 昊, 暮, 欤, 却, 趁,\n",
      "Nearest to 飞: 飘, 翩, 随, 芦, 归, 凋, 钗, 巘,\n",
      "Nearest to 烟: 雾, 云, 逗, 暝, 霭, 辽, 绥, 蒿,\n",
      "Nearest to 明: 瘳, 搴, 姮, 当, 漪, 十, 圆, 光,\n",
      "Nearest to 看: 听, 向, 仔, 问, 起, 扪, 垩, 说,\n",
      "Nearest to 东: 西, 北, 南, 罡, 迅, 斜, 诘, 洛,\n",
      "Nearest to 红: 钚, 暇, 甑, 菁, 垢, 骎, 眇, 花,\n",
      "Nearest to 处: 意, 警, □, 淝, 便, 曾, 时, 福,\n",
      "Nearest to 醉: 笑, 醒, 岖, 糜, 嫌, 救, 妨, 析,\n",
      "Average loss at step  212000 :  3.98713250041\n",
      "Average loss at step  214000 :  3.99942236567\n",
      "Average loss at step  216000 :  3.95353518438\n",
      "Average loss at step  218000 :  3.97451279199\n",
      "Average loss at step  220000 :  4.00823091578\n",
      "Nearest to ）: ·, 。, 祁, 之, 词, 芍, 鹈, 芰,\n",
      "Nearest to 南: 西, 北, 东, 荔, 蓠, 怃, 头, 屃,\n",
      "Nearest to 山: 峰, 岩, 岫, 水, 濑, 压, 堵, 瑁,\n",
      "Nearest to 梦: ., 这, 恨, 魂, 话, 椠, 瞒, 苕,\n",
      "Nearest to 情: 拏, 愁, 恨, 意, 感, 恙, 鞘, 怨,\n",
      "Nearest to 小: 蓝, 贪, 移, 卢, 椠, 好, 集, 柯,\n",
      "Nearest to 为: 与, 似, 庄, 借, 同, 向, 共, 瓷,\n",
      "Nearest to 去: 归, 来, 幺, 昊, 欤, 却, 暮, 骑,\n",
      "Nearest to 飞: 飘, 翩, 钗, 谿, 凋, 群, 鹳, 芦,\n",
      "Nearest to 烟: 雾, 云, 暝, 辽, 霭, 逗, 杳, 绥,\n",
      "Nearest to 明: 搴, 姮, 瘳, 圆, 当, 华, 十, 漪,\n",
      "Nearest to 看: 听, 仔, 问, 向, 垩, 起, 扪, 说,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 罡, 洛, 航,\n",
      "Nearest to 红: 暇, 钚, 甑, 菁, 花, 垢, 骎, 厕,\n",
      "Nearest to 处: 意, 福, 便, 常, 警, □, 更, 嶷,\n",
      "Nearest to 醉: 笑, 醒, 嫌, 岖, 糜, 妨, 你, 鲊,\n",
      "Average loss at step  222000 :  3.98798544288\n",
      "Average loss at step  224000 :  4.00978142464\n",
      "Average loss at step  226000 :  4.07506379247\n",
      "Average loss at step  228000 :  4.04920820189\n",
      "Average loss at step  230000 :  4.05961001277\n",
      "Nearest to ）: 。, ·, 祁, 芍, 盎, 粮, 卯, 之,\n",
      "Nearest to 南: 西, 北, 东, 怃, 荔, 蓠, 头, 屃,\n",
      "Nearest to 山: 峰, 岩, 岫, 水, 濑, 枧, 瑁, 枪,\n",
      "Nearest to 梦: 恨, ., 魂, 椠, 这, 话, 瞒, 忌,\n",
      "Nearest to 情: 愁, 拏, 恨, 意, 恙, 绪, 黯, 怨,\n",
      "Nearest to 小: 蓝, 移, 集, 傍, 好, 贷, 畔, 蓬,\n",
      "Nearest to 为: 与, 似, 共, 同, 借, 庄, 伴, 向,\n",
      "Nearest to 去: 归, 来, 幺, 暮, 欤, 昊, 赣, 讨,\n",
      "Nearest to 飞: 飘, 翩, 钗, 谿, 群, 凋, 巘, 芦,\n",
      "Nearest to 烟: 雾, 暝, 云, 辽, 逗, 霭, 荫, 漠,\n",
      "Nearest to 明: 瘳, 姮, 当, 圆, 华, 搴, 缺, 娄,\n",
      "Nearest to 看: 听, 向, 仔, 对, 垩, 说, 起, 扪,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 罡, 航, 诘,\n",
      "Nearest to 红: 甑, 暇, 钚, 菁, 垢, 汗, 鄜, 宕,\n",
      "Nearest to 处: 意, 便, 福, 淝, 警, 更, □, 句,\n",
      "Nearest to 醉: 笑, 醒, 糜, 岖, 嫌, 困, 逡, 睡,\n",
      "Average loss at step  232000 :  4.0379997406\n",
      "Average loss at step  234000 :  4.01772546935\n",
      "Average loss at step  236000 :  4.06854555881\n",
      "Average loss at step  238000 :  4.03865618277\n",
      "Average loss at step  240000 :  3.91986042535\n",
      "Nearest to ）: ·, 祁, 吕, 盎, 粮, 芍, 之, 词,\n",
      "Nearest to 南: 西, 北, 荔, 怃, 东, 蓠, 闽, 屃,\n",
      "Nearest to 山: 峰, 岫, 岩, 楼, 濑, 水, 嚏, 枧,\n",
      "Nearest to 梦: 恨, 魂, ., 这, 话, 椠, 事, 瞒,\n",
      "Nearest to 情: 恨, 愁, 意, 拏, 恙, 感, 怨, 悲,\n",
      "Nearest to 小: 蓝, 移, 椠, 画, 好, 扁, 集, 傍,\n",
      "Nearest to 为: 与, 似, 同, 共, 庄, 借, 因, 向,\n",
      "Nearest to 去: 归, 来, 幺, 欤, 暮, 昊, 别, 却,\n",
      "Nearest to 飞: 飘, 翩, 随, 钗, 归, 群, 巘, 谿,\n",
      "Nearest to 烟: 雾, 逗, 云, 暝, 霭, 辽, 鸽, 荫,\n",
      "Nearest to 明: 瘳, 姮, 光, 搴, 当, 圆, 漪, 十,\n",
      "Nearest to 看: 听, 仔, 向, 扪, 起, 问, 阅, 垩,\n",
      "Nearest to 东: 西, 北, 南, 斜, 罡, 迅, 洛, 春,\n",
      "Nearest to 红: 钚, 暇, 甑, 菁, 杏, 花, 骎, 眇,\n",
      "Nearest to 处: 意, 警, 便, 淝, 鞬, 曾, 常, 福,\n",
      "Nearest to 醉: 笑, 醒, 岖, 糜, 嫌, 救, 逡, 析,\n",
      "Average loss at step  242000 :  3.96737768447\n",
      "Average loss at step  244000 :  3.99130782247\n",
      "Average loss at step  246000 :  3.94976535332\n",
      "Average loss at step  248000 :  3.95696111006\n",
      "Average loss at step  250000 :  3.98196798778\n",
      "Nearest to ）: ·, 祁, 。, 之, 芍, 词, 菩, 鹈,\n",
      "Nearest to 南: 北, 西, 东, 蓠, 怃, 荔, 头, 闽,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 濑, 堵, 压, 嚏,\n",
      "Nearest to 梦: 魂, ., 恨, 这, 话, 椠, 瞒, 苕,\n",
      "Nearest to 情: 拏, 愁, 意, 恨, 恙, 感, 绪, 悲,\n",
      "Nearest to 小: 蓝, 移, 集, 椠, 蓬, 好, 贪, 瓞,\n",
      "Nearest to 为: 与, 似, 借, 庄, 向, 共, 同, 偏,\n",
      "Nearest to 去: 归, 来, 欤, 幺, 暮, 却, 昊, 骑,\n",
      "Nearest to 飞: 飘, 翩, 钗, 谿, 凋, 流, 群, 幻,\n",
      "Nearest to 烟: 雾, 云, 暝, 霭, 逗, 辽, 蒿, 绥,\n",
      "Nearest to 明: 瘳, 搴, 姮, 圆, 当, 光, 华, 十,\n",
      "Nearest to 看: 听, 仔, 问, 起, 垩, 向, 扪, 阅,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 罡, 讨, 洛,\n",
      "Nearest to 红: 钚, 暇, 甑, 菁, 杏, 苞, 汗, 拳,\n",
      "Nearest to 处: 意, 福, □, 便, 警, 更, 嶷, 常,\n",
      "Nearest to 醉: 笑, 醒, 岖, 嫌, 糜, 困, 你, 妨,\n",
      "Average loss at step  252000 :  3.98225984561\n",
      "Average loss at step  254000 :  4.02357959032\n",
      "Average loss at step  256000 :  4.05069444048\n",
      "Average loss at step  258000 :  4.03991573071\n",
      "Average loss at step  260000 :  4.04521254027\n",
      "Nearest to ）: 。, ·, 祁, 芍, 词, 粮, 盎, 赋,\n",
      "Nearest to 南: 北, 西, 东, 怃, 荔, 蓠, 头, 屃,\n",
      "Nearest to 山: 峰, 岩, 岫, 水, 瑁, 枪, 濑, 枧,\n",
      "Nearest to 梦: 恨, 魂, ., 椠, 话, 忌, 这, 瞒,\n",
      "Nearest to 情: 愁, 拏, 恨, 意, 恙, 绪, 黯, 悲,\n",
      "Nearest to 小: 蓝, 移, 蓬, 好, 集, 贷, 傍, 骞,\n",
      "Nearest to 为: 与, 似, 共, 同, 借, 赠, 庄, 问,\n",
      "Nearest to 去: 归, 来, 幺, 欤, 暮, 却, 昊, 讨,\n",
      "Nearest to 飞: 飘, 翩, 钗, 群, 谿, 巘, 凋, 流,\n",
      "Nearest to 烟: 雾, 逗, 辽, 暝, 霭, 云, 荫, 鸽,\n",
      "Nearest to 明: 瘳, 当, 圆, 姮, 华, 搴, 娄, 缺,\n",
      "Nearest to 看: 听, 仔, 向, 对, 垩, 阅, 问, 拜,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 航, 罡, 洛,\n",
      "Nearest to 红: 甑, 钚, 暇, 菁, 垢, 汗, 鄜, 拳,\n",
      "Nearest to 处: 意, 警, 便, 嶷, 淝, 福, □, 句,\n",
      "Nearest to 醉: 笑, 醒, 岖, 困, 糜, 嫌, 睡, 析,\n",
      "Average loss at step  262000 :  4.01152625883\n",
      "Average loss at step  264000 :  4.0145253222\n",
      "Average loss at step  266000 :  4.05316771698\n",
      "Average loss at step  268000 :  3.99494427431\n",
      "Average loss at step  270000 :  3.93749886656\n",
      "Nearest to ）: ·, 祁, 吕, 粮, 芍, 盎, 之, 词,\n",
      "Nearest to 南: 西, 北, 怃, 东, 荔, 蓠, 闽, 屃,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 楼, 嚏, 枧, 濑,\n",
      "Nearest to 梦: 恨, 魂, ., 这, 椠, 话, 瞒, 苕,\n",
      "Nearest to 情: 恨, 意, 愁, 拏, 恙, 感, 悲, 怨,\n",
      "Nearest to 小: 蓝, 移, 椠, 画, 好, 扁, 打, 集,\n",
      "Nearest to 为: 与, 似, 共, 同, 因, 借, 庄, 偏,\n",
      "Nearest to 去: 归, 来, 幺, 欤, 暮, 别, 昊, 却,\n",
      "Nearest to 飞: 飘, 翩, 随, 群, 凫, 巘, 谿, 钗,\n",
      "Nearest to 烟: 雾, 逗, 暝, 霭, 云, 鸽, 辽, 蒿,\n",
      "Nearest to 明: 瘳, 姮, 光, 搴, 圆, 十, 当, 昨,\n",
      "Nearest to 看: 听, 仔, 阅, 问, 起, 向, 说, 垩,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 罡, 洛, 淅,\n",
      "Nearest to 红: 钚, 暇, 菁, 甑, 杏, 汗, 骎, 眇,\n",
      "Nearest to 处: 意, 警, □, 便, 更, 淝, 鞬, 憾,\n",
      "Nearest to 醉: 笑, 醒, 岖, 糜, 嫌, 逡, 鲊, 困,\n",
      "Average loss at step  272000 :  3.95470135152\n",
      "Average loss at step  274000 :  3.97793890119\n",
      "Average loss at step  276000 :  3.93442324972\n",
      "Average loss at step  278000 :  3.94786887449\n",
      "Average loss at step  280000 :  3.96157849252\n",
      "Nearest to ）: ·, 祁, 之, 。, 芍, 词, 芰, 鹈,\n",
      "Nearest to 南: 北, 西, 东, 蓠, 怃, 荔, 闽, 头,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 嚏, 濑, 压, 枧,\n",
      "Nearest to 梦: 魂, ., 恨, 这, 椠, 苕, 瞒, 话,\n",
      "Nearest to 情: 拏, 意, 愁, 恨, 悲, 感, 恙, 绪,\n",
      "Nearest to 小: 蓝, 移, 好, 蓬, 集, 椠, 骞, 贪,\n",
      "Nearest to 为: 与, 似, 共, 偏, 借, 是, 同, 因,\n",
      "Nearest to 去: 归, 来, 欤, 幺, 却, 暮, 崎, 讨,\n",
      "Nearest to 飞: 飘, 翩, 钗, 凋, 鹳, 谿, 群, 流,\n",
      "Nearest to 烟: 雾, 暝, 云, 霭, 逗, 辽, 杳, 蒿,\n",
      "Nearest to 明: 圆, 瘳, 姮, 当, 光, 搴, 华, 照,\n",
      "Nearest to 看: 听, 仔, 起, 阅, 垩, 拜, 扪, 堆,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 罡, 航, 讨,\n",
      "Nearest to 红: 钚, 暇, 甑, 菁, 杏, 垢, 苞, 汗,\n",
      "Nearest to 处: 意, □, 嶷, 福, 警, 便, 更, 地,\n",
      "Nearest to 醉: 笑, 醒, 岖, 嫌, 糜, 困, 睡, 削,\n",
      "Average loss at step  282000 :  3.98133635616\n",
      "Average loss at step  284000 :  4.01983172834\n",
      "Average loss at step  286000 :  4.03409228146\n",
      "Average loss at step  288000 :  4.03073245418\n",
      "Average loss at step  290000 :  4.0377689575\n",
      "Nearest to ）: 。, ·, 祁, \n",
      ", 芍, 赋, 鹈, 词,\n",
      "Nearest to 南: 西, 北, 东, 怃, 荔, 蓠, 头, 闽,\n",
      "Nearest to 山: 峰, 岩, 岫, 水, 楼, 濑, 枪, 枧,\n",
      "Nearest to 梦: 魂, 恨, ., 椠, 话, 忌, 这, 事,\n",
      "Nearest to 情: 愁, 拏, 恨, 意, 恙, 绪, 悲, 黯,\n",
      "Nearest to 小: 蓝, 好, 移, 集, 蓬, 打, 贷, 骞,\n",
      "Nearest to 为: 与, 似, 共, 同, 访, 伴, 赠, 因,\n",
      "Nearest to 去: 归, 来, 欤, 暮, 幺, 赣, 趁, 却,\n",
      "Nearest to 飞: 飘, 翩, 群, 钗, 谿, 巘, 鹳, 凋,\n",
      "Nearest to 烟: 雾, 霭, 逗, 辽, 暝, 云, 荫, 漠,\n",
      "Nearest to 明: 瘳, 圆, 姮, 当, 娄, 华, 缺, 光,\n",
      "Nearest to 看: 听, 仔, 对, 向, 阅, 垩, 堆, 拜,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 航, 淅, 罡,\n",
      "Nearest to 红: 甑, 钚, 菁, 暇, 汗, 春, 拳, 苞,\n",
      "Nearest to 处: 意, 更, 警, 便, □, 福, 句, 嶷,\n",
      "Nearest to 醉: 笑, 醒, 岖, 困, 糜, 睡, 嫌, 析,\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average loss at step  292000 :  3.99307673681\n",
      "Average loss at step  294000 :  4.02047376442\n",
      "Average loss at step  296000 :  4.02819625533\n",
      "Average loss at step  298000 :  3.97645965648\n",
      "Average loss at step  300000 :  3.91990864933\n",
      "Nearest to ）: ·, 祁, 粮, 。, 吕, 盎, 芍, 之,\n",
      "Nearest to 南: 北, 西, 东, 怃, 蓠, 荔, 闽, 屃,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 楼, 嚏, 枧, 岭,\n",
      "Nearest to 梦: 魂, 恨, ., 这, 椠, 话, 事, 胶,\n",
      "Nearest to 情: 恨, 愁, 意, 拏, 恙, 绪, 诉, 怨,\n",
      "Nearest to 小: 蓝, 移, 好, 画, 儿, 打, 椠, 扁,\n",
      "Nearest to 为: 与, 似, 因, 共, 偏, 借, 同, 伴,\n",
      "Nearest to 去: 归, 来, 欤, 暮, 幺, 却, 趁, 昊,\n",
      "Nearest to 飞: 飘, 翩, 随, 群, 凫, 鹳, 谿, 钗,\n",
      "Nearest to 烟: 雾, 逗, 霭, 云, 暝, 鸽, 辽, 漠,\n",
      "Nearest to 明: 瘳, 圆, 光, 姮, 搴, 晓, 昨, 当,\n",
      "Nearest to 看: 阅, 仔, 听, 起, 问, 向, 垩, 扪,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 罡, 淅, 洛,\n",
      "Nearest to 红: 钚, 菁, 暇, 甑, 杏, 花, 骎, 汗,\n",
      "Nearest to 处: 意, 警, 曾, 便, 憾, 鞬, 更, 嶷,\n",
      "Nearest to 醉: 笑, 醒, 岖, 糜, 困, 睡, 赫, 钺,\n",
      "Average loss at step  302000 :  3.95720725679\n",
      "Average loss at step  304000 :  3.9403893714\n",
      "Average loss at step  306000 :  3.94329544127\n",
      "Average loss at step  308000 :  3.94297428429\n",
      "Average loss at step  310000 :  3.96042367864\n",
      "Nearest to ）: ·, 祁, 。, 之, 芍, 鹈, 芰, 羝,\n",
      "Nearest to 南: 北, 西, 东, 蓠, 怃, 荔, 闽, 屃,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 嚏, 岭, 濑, 压,\n",
      "Nearest to 梦: ., 魂, 恨, 椠, 这, 苕, 胶, 谠,\n",
      "Nearest to 情: 意, 恨, 愁, 拏, 恙, 诉, 绪, 悲,\n",
      "Nearest to 小: 蓝, 移, 好, 蓬, 集, 椠, 瓞, 辕,\n",
      "Nearest to 为: 与, 似, 因, 共, 借, 偏, 被, 是,\n",
      "Nearest to 去: 归, 来, 欤, 暮, 却, 幺, 崎, 讨,\n",
      "Nearest to 飞: 飘, 翩, 谿, 钗, 鹳, 群, 凋, 坠,\n",
      "Nearest to 烟: 雾, 云, 霭, 暝, 逗, 辽, 杳, 鸽,\n",
      "Nearest to 明: 圆, 瘳, 光, 姮, 当, 搴, 华, 十,\n",
      "Nearest to 看: 仔, 听, 起, 阅, 垩, 说, 拜, 堆,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 罡, 航, 洛,\n",
      "Nearest to 红: 钚, 暇, 甑, 菁, 苞, 杏, 衬, 汗,\n",
      "Nearest to 处: 意, □, 嶷, 便, 福, 警, 鞬, 时,\n",
      "Nearest to 醉: 笑, 岖, 醒, 嫌, 困, 糜, 削, 妨,\n",
      "Average loss at step  312000 :  3.96955031383\n",
      "Average loss at step  314000 :  4.0278908025\n",
      "Average loss at step  316000 :  4.01406866503\n",
      "Average loss at step  318000 :  4.03215249133\n",
      "Average loss at step  320000 :  4.01687647915\n",
      "Nearest to ）: 。, ·, 祁, \n",
      ", 芍, 鹈, 浣, 词,\n",
      "Nearest to 南: 北, 西, 东, 怃, 蓠, 荔, 闽, 屃,\n",
      "Nearest to 山: 峰, 岩, 岫, 水, 楼, 濑, 枪, 瑁,\n",
      "Nearest to 梦: 恨, 魂, 椠, ., 话, 忌, 这, 堡,\n",
      "Nearest to 情: 愁, 拏, 恨, 意, 恙, 绪, 黯, 怨,\n",
      "Nearest to 小: 蓝, 好, 集, 打, 蓬, 贷, 移, 谬,\n",
      "Nearest to 为: 与, 似, 共, 访, 赠, 伴, 因, 同,\n",
      "Nearest to 去: 归, 来, 欤, 暮, 赣, 幺, 崎, 趁,\n",
      "Nearest to 飞: 飘, 翩, 群, 谿, 钗, 凫, 坠, 鹳,\n",
      "Nearest to 烟: 雾, 逗, 霭, 辽, 暝, 云, 鸽, 漠,\n",
      "Nearest to 明: 瘳, 圆, 姮, 当, 搴, 娄, 光, 缺,\n",
      "Nearest to 看: 听, 仔, 向, 对, 阅, 垩, 拜, 说,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 航, 淅, 罡,\n",
      "Nearest to 红: 钚, 甑, 暇, 菁, 汗, 杏, 苞, 拳,\n",
      "Nearest to 处: 意, □, 更, 警, 便, 嶷, 句, 鞬,\n",
      "Nearest to 醉: 笑, 困, 醒, 岖, 糜, 析, 睡, 逡,\n",
      "Average loss at step  322000 :  3.98520955777\n",
      "Average loss at step  324000 :  4.01884040415\n",
      "Average loss at step  326000 :  4.01445270193\n",
      "Average loss at step  328000 :  3.9391399554\n",
      "Average loss at step  330000 :  3.92591182721\n",
      "Nearest to ）: ·, 之, 。, 祁, 吕, \n",
      ", 粮, 词,\n",
      "Nearest to 南: 北, 西, 东, 怃, 蓠, 闽, 荔, 屃,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 楼, 岭, 嚏, 崖,\n",
      "Nearest to 梦: 魂, 恨, ., 这, 椠, 话, 苕, 热,\n",
      "Nearest to 情: 恨, 愁, 意, 拏, 恙, 诉, 绪, 怨,\n",
      "Nearest to 小: 蓝, 画, 移, 好, 瓞, 打, 蓬, 儿,\n",
      "Nearest to 为: 与, 似, 共, 因, 如, 向, 借, 同,\n",
      "Nearest to 去: 归, 来, 欤, 幺, 暮, 别, 却, 崎,\n",
      "Nearest to 飞: 飘, 翩, 群, 谿, 归, 巘, 凋, 钗,\n",
      "Nearest to 烟: 雾, 霭, 逗, 云, 暝, 鸽, 辽, 漠,\n",
      "Nearest to 明: 瘳, 姮, 光, 圆, 搴, 当, 昨, 娄,\n",
      "Nearest to 看: 仔, 阅, 听, 起, 问, 说, 扪, 把,\n",
      "Nearest to 东: 西, 北, 南, 斜, 淅, 迅, 洛, 罡,\n",
      "Nearest to 红: 钚, 菁, 暇, 花, 甑, 杏, 岖, 苞,\n",
      "Nearest to 处: 意, 曾, 警, □, 便, 憾, 鞬, 嶷,\n",
      "Nearest to 醉: 笑, 糜, 醒, 岖, 困, 赫, 救, 睡,\n",
      "Average loss at step  332000 :  3.96671051538\n",
      "Average loss at step  334000 :  3.917367993\n",
      "Average loss at step  336000 :  3.93038768923\n",
      "Average loss at step  338000 :  3.93785092014\n",
      "Average loss at step  340000 :  3.94327095687\n",
      "Nearest to ）: ·, 祁, 。, 芍, 之, \n",
      ", 鹈, 菩,\n",
      "Nearest to 南: 北, 西, 东, 怃, 蓠, 荔, 闽, 郊,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 嚏, 岭, 濑, 压,\n",
      "Nearest to 梦: ., 魂, 椠, 恨, 苕, 这, 胶, 曦,\n",
      "Nearest to 情: 恨, 愁, 意, 拏, 诉, 恙, 绪, 悲,\n",
      "Nearest to 小: 蓝, 好, 集, 蓬, 移, 打, 贪, 瓞,\n",
      "Nearest to 为: 与, 似, 共, 被, 因, 是, 向, 属,\n",
      "Nearest to 去: 归, 来, 欤, 却, 暮, 幺, 崎, 讨,\n",
      "Nearest to 飞: 飘, 翩, 鹳, 谿, 钗, 卷, 坠, 凋,\n",
      "Nearest to 烟: 雾, 霭, 云, 逗, 暝, 辽, 鸽, 蒿,\n",
      "Nearest to 明: 瘳, 圆, 光, 姮, 当, 华, 搴, 照,\n",
      "Nearest to 看: 说, 听, 仔, 起, 阅, 垩, 问, 拜,\n",
      "Nearest to 东: 西, 北, 南, 斜, 航, 迅, 罡, 淅,\n",
      "Nearest to 红: 钚, 暇, 甑, 菁, 杏, 苞, 衬, 花,\n",
      "Nearest to 处: 意, 便, 嶷, □, 地, 时, 鞬, 更,\n",
      "Nearest to 醉: 笑, 醒, 糜, 困, 岖, 嫌, 拚, 病,\n",
      "Average loss at step  342000 :  3.97181605041\n",
      "Average loss at step  344000 :  4.01763996422\n",
      "Average loss at step  346000 :  3.99987240267\n",
      "Average loss at step  348000 :  4.0394623456\n",
      "Average loss at step  350000 :  3.9953777132\n",
      "Nearest to ）: 。, ·, 祁, \n",
      ", 芍, 灌, 词, 哨,\n",
      "Nearest to 南: 北, 西, 东, 怃, 蓠, 荔, 闽, 屃,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 濑, 望, 楼, 岭,\n",
      "Nearest to 梦: 恨, 魂, 椠, ., 话, 事, 这, 苕,\n",
      "Nearest to 情: 愁, 意, 拏, 恨, 恙, 绪, 黯, 悲,\n",
      "Nearest to 小: 蓝, 好, 打, 移, 蓬, 集, 贷, 谬,\n",
      "Nearest to 为: 与, 共, 似, 伴, 向, 访, 赠, 因,\n",
      "Nearest to 去: 归, 来, 欤, 暮, 趁, 却, 赣, 讨,\n",
      "Nearest to 飞: 飘, 翩, 群, 谿, 钗, 凫, 坠, 鹳,\n",
      "Nearest to 烟: 雾, 霭, 逗, 暝, 辽, 鸽, 漠, 云,\n",
      "Nearest to 明: 瘳, 圆, 姮, 当, 华, 光, 娄, 缺,\n",
      "Nearest to 看: 听, 仔, 对, 阅, 向, 说, 垩, 把,\n",
      "Nearest to 东: 西, 北, 南, 斜, 迅, 航, 淅, 罡,\n",
      "Nearest to 红: 钚, 甑, 菁, 暇, 杏, 苞, 汗, 岖,\n",
      "Nearest to 处: 意, 更, 便, □, 句, 憾, 嶷, 警,\n",
      "Nearest to 醉: 笑, 困, 醒, 糜, 岖, 睡, 析, 削,\n",
      "Average loss at step  352000 :  3.98424518943\n",
      "Average loss at step  354000 :  4.00971029687\n",
      "Average loss at step  356000 :  4.01285564852\n",
      "Average loss at step  358000 :  3.90166082537\n",
      "Average loss at step  360000 :  3.93727813947\n",
      "Nearest to ）: ·, 。, 祁, 之, 吕, \n",
      ", 含, 芍,\n",
      "Nearest to 南: 北, 西, 东, 怃, 蓠, 闽, 荔, 屃,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 嚏, 楼, 岭, 莆,\n",
      "Nearest to 梦: 魂, 恨, ., 椠, 这, 热, 苕, 话,\n",
      "Nearest to 情: 意, 恨, 愁, 拏, 恙, 诉, 黯, 绪,\n",
      "Nearest to 小: 蓝, 打, 移, 画, 儿, 好, 扁, 瓞,\n",
      "Nearest to 为: 与, 似, 共, 因, 同, 借, 向, 被,\n",
      "Nearest to 去: 归, 来, 欤, 暮, 幺, 趁, 却, 别,\n",
      "Nearest to 飞: 飘, 翩, 群, 凫, 谿, 璈, 归, 坠,\n",
      "Nearest to 烟: 雾, 霭, 逗, 云, 暝, 鸽, 辽, 漠,\n",
      "Nearest to 明: 瘳, 圆, 光, 姮, 搴, 茏, 衿, 昨,\n",
      "Nearest to 看: 听, 仔, 阅, 说, 问, 起, 垩, 把,\n",
      "Nearest to 东: 西, 北, 南, 斜, 航, 淅, 洛, 迅,\n",
      "Nearest to 红: 钚, 菁, 甑, 暇, 花, 苞, 岖, 杏,\n",
      "Nearest to 处: 意, □, 警, 便, 曾, 憾, 句, 鞬,\n",
      "Nearest to 醉: 笑, 岖, 糜, 醒, 困, 睡, 赫, 析,\n",
      "Average loss at step  362000 :  3.95335782158\n",
      "Average loss at step  364000 :  3.89961593807\n",
      "Average loss at step  366000 :  3.92738939536\n",
      "Average loss at step  368000 :  3.94747912681\n",
      "Average loss at step  370000 :  3.92477956223\n",
      "Nearest to ）: ·, 。, 祁, ，, 菩, 芍, 之, \n",
      ",\n",
      "Nearest to 南: 北, 西, 东, 蓠, 怃, 闽, 荔, 屃,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 岭, 嚏, 瑁, 懿,\n",
      "Nearest to 梦: 魂, ., 椠, 恨, 苕, 谠, 胶, 这,\n",
      "Nearest to 情: 恨, 意, 愁, 拏, 恙, 绪, 诉, 感,\n",
      "Nearest to 小: 蓝, 好, 集, 打, 蓬, 移, 贪, □,\n",
      "Nearest to 为: 与, 似, 共, 向, 因, 被, 同, 是,\n",
      "Nearest to 去: 归, 来, 欤, 却, 暮, 幺, 崎, 讨,\n",
      "Nearest to 飞: 飘, 翩, 谿, 鹳, 群, 卷, 坠, 钗,\n",
      "Nearest to 烟: 雾, 霭, 逗, 暝, 云, 辽, 鸽, 蒿,\n",
      "Nearest to 明: 瘳, 光, 圆, 搴, 姮, 跚, 华, 荧,\n",
      "Nearest to 看: 阅, 听, 仔, 说, 起, 拜, 垩, 问,\n",
      "Nearest to 东: 西, 北, 南, 斜, 航, 罡, 迅, 淅,\n",
      "Nearest to 红: 钚, 暇, 甑, 苞, 衬, 杏, 菁, 花,\n",
      "Nearest to 处: □, 意, 便, 时, 地, 鞬, 更, 限,\n",
      "Nearest to 醉: 笑, 岖, 困, 醒, 糜, 拚, 睡, 病,\n",
      "Average loss at step  372000 :  3.96172592318\n",
      "Average loss at step  374000 :  4.0078535018\n",
      "Average loss at step  376000 :  3.98610418475\n",
      "Average loss at step  378000 :  4.02041220427\n",
      "Average loss at step  380000 :  4.00751867962\n",
      "Nearest to ）: 。, ·, 祁, \n",
      ", 芍, 灌, 哨, 词,\n",
      "Nearest to 南: 北, 西, 东, 怃, 蓠, 荔, 闽, 屃,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 濑, 楼, 望, 岭,\n",
      "Nearest to 梦: 魂, 椠, 恨, ., 话, 苕, 醉, 事,\n",
      "Nearest to 情: 愁, 恨, 意, 拏, 恙, 绪, 悲, 黯,\n",
      "Nearest to 小: 蓝, 好, 打, 蓬, 移, 集, 贷, 儿,\n",
      "Nearest to 为: 与, 似, 共, 因, 赠, 访, 借, 向,\n",
      "Nearest to 去: 归, 来, 欤, 却, 赣, 暮, 崎, 趁,\n",
      "Nearest to 飞: 飘, 翩, 谿, 凫, 群, 坠, 钗, 流,\n",
      "Nearest to 烟: 雾, 霭, 暝, 逗, 辽, 漠, 云, 鸽,\n",
      "Nearest to 明: 瘳, 圆, 姮, 华, 当, 搴, 光, 跚,\n",
      "Nearest to 看: 听, 仔, 对, 阅, 向, 把, 趁, 拜,\n",
      "Nearest to 东: 西, 北, 南, 斜, 航, 迅, 淅, 罡,\n",
      "Nearest to 红: 钚, 甑, 菁, 苞, 杏, 暇, 花, 汗,\n",
      "Nearest to 处: 意, 更, 句, 便, □, 憾, 地, 警,\n",
      "Nearest to 醉: 笑, 困, 醒, 糜, 岖, 梦, 睡, 析,\n",
      "Average loss at step  382000 :  3.97351918471\n",
      "Average loss at step  384000 :  4.00694198132\n",
      "Average loss at step  386000 :  3.99833798397\n",
      "Average loss at step  388000 :  3.88437852871\n",
      "Average loss at step  390000 :  3.92209726238\n",
      "Nearest to ）: ·, 之, 。, 祁, \n",
      ", 吕, 含, 哨,\n",
      "Nearest to 南: 北, 西, 东, 怃, 蓠, 闽, 荔, 屃,\n",
      "Nearest to 山: 峰, 岫, 岩, 水, 楼, 岭, 嚏, 崖,\n",
      "Nearest to 梦: 魂, ., 恨, 椠, 热, 胶, 话, 苕,\n",
      "Nearest to 情: 恨, 意, 愁, 拏, 恙, 诉, 悲, 黯,\n",
      "Nearest to 小: 蓝, 打, 好, 移, 碧, 画, 儿, 骞,\n",
      "Nearest to 为: 与, 共, 似, 因, 向, 被, 同, 借,\n",
      "Nearest to 去: 归, 来, 欤, 暮, 幺, 向, 崎, 趁,\n",
      "Nearest to 飞: 飘, 翩, 凫, 群, 谿, 璈, 坠, 归,\n",
      "Nearest to 烟: 雾, 霭, 逗, 云, 暝, 鸽, 辽, 漠,\n",
      "Nearest to 明: 瘳, 光, 圆, 姮, 搴, 昨, 晓, 茏,\n",
      "Nearest to 看: 阅, 仔, 听, 说, 问, 起, 趁, 拜,\n",
      "Nearest to 东: 西, 北, 南, 斜, 洛, 淅, 罡, 航,\n",
      "Nearest to 红: 钚, 花, 菁, 暇, 甑, 苞, 杏, 岖,\n",
      "Nearest to 处: 意, 警, □, 便, 曾, 憾, 鞬, 地,\n",
      "Nearest to 醉: 笑, 困, 岖, 糜, 醒, 睡, 垫, 析,\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average loss at step  392000 :  3.96047914398\n",
      "Average loss at step  394000 :  3.89566869152\n",
      "Average loss at step  396000 :  3.92566693008\n",
      "Average loss at step  398000 :  3.93204687601\n",
      "Average loss at step  400000 :  3.92570940888\n",
      "Nearest to ）: 。, ·, 祁, 之, ，, 菩, 芍, 灌,\n",
      "Nearest to 南: 北, 西, 东, 蓠, 怃, 闽, 屃, 荔,\n",
      "Nearest to 山: 峰, 岩, 岫, 水, 岭, 瑁, 嚏, 楼,\n",
      "Nearest to 梦: 魂, ., 椠, 苕, 恨, 胶, 谠, 猿,\n",
      "Nearest to 情: 恨, 愁, 意, 拏, 恙, 诉, 绪, 悲,\n",
      "Nearest to 小: 蓝, 集, 好, 打, 移, 蓬, 璁, 谬,\n",
      "Nearest to 为: 与, 似, 因, 属, 共, 赠, 同, 作,\n",
      "Nearest to 去: 归, 来, 欤, 幺, 崎, 讨, 暮, 却,\n",
      "Nearest to 飞: 翩, 飘, 坠, 鹳, 谿, 凫, 卷, 钗,\n",
      "Nearest to 烟: 雾, 霭, 逗, 暝, 辽, 云, 鸽, 蒿,\n",
      "Nearest to 明: 瘳, 光, 圆, 姮, 搴, 跚, 荧, 华,\n",
      "Nearest to 看: 仔, 阅, 听, 说, 拜, 起, 问, 垩,\n",
      "Nearest to 东: 西, 北, 南, 斜, 航, 迅, 罡, 淅,\n",
      "Nearest to 红: 钚, 暇, 杏, 甑, 衬, 苞, 菁, 麹,\n",
      "Nearest to 处: 意, 便, 时, 限, 鞬, □, 更, 嶷,\n",
      "Nearest to 醉: 笑, 困, 拚, 醒, 糜, 岖, 睡, 病,\n"
     ]
    }
   ],
   "source": [
    "# Step 5: Begin training.\n",
    "num_steps = 400001\n",
    "\n",
    "with tf.Session(graph=graph) as session:\n",
    "  # We must initialize all variables before we use them.\n",
    "  init.run()\n",
    "  print('Initialized')\n",
    "\n",
    "  average_loss = 0\n",
    "  for step in xrange(num_steps):\n",
    "    batch_inputs, batch_labels = generate_batch(\n",
    "        batch_size, num_skips, skip_window)\n",
    "    feed_dict = {train_inputs: batch_inputs, train_labels: batch_labels}\n",
    "\n",
    "    # We perform one update step by evaluating the optimizer op (including it\n",
    "    # in the list of returned values for session.run()\n",
    "    _, loss_val = session.run([optimizer, loss], feed_dict=feed_dict)\n",
    "    average_loss += loss_val\n",
    "\n",
    "    if step % 2000 == 0:\n",
    "      if step > 0:\n",
    "        average_loss /= 2000\n",
    "      # The average loss is an estimate of the loss over the last 2000 batches.\n",
    "      print('Average loss at step ', step, ': ', average_loss)\n",
    "      average_loss = 0\n",
    "\n",
    "    # Note that this is expensive (~20% slowdown if computed every 500 steps)\n",
    "    if step % 10000 == 0:\n",
    "      sim = similarity.eval()\n",
    "      for i in xrange(valid_size):\n",
    "        valid_word = reverse_dictionary[valid_examples[i]]\n",
    "        top_k = 8  # number of nearest neighbors\n",
    "        nearest = (-sim[i, :]).argsort()[1:top_k + 1]\n",
    "        log_str = 'Nearest to %s:' % valid_word\n",
    "        for k in xrange(top_k):\n",
    "          close_word = reverse_dictionary.get(nearest[k],'not exist')\n",
    "          log_str = '%s %s,' % (log_str, close_word)\n",
    "        print(log_str)\n",
    "  final_embeddings = normalized_embeddings.eval()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Step 6: Visualize the embeddings.\n",
    "\n",
    "\n",
    "# pylint: disable=missing-docstring\n",
    "# Function to draw visualization of distance between embeddings.\n",
    "def plot_with_labels(low_dim_embs, labels, filename):\n",
    "  assert low_dim_embs.shape[0] >= len(labels), 'More labels than embeddings'\n",
    "  plt.figure(figsize=(18, 18))  # in inches\n",
    "  for i, label in enumerate(labels):\n",
    "    x, y = low_dim_embs[i, :]\n",
    "    plt.scatter(x, y)\n",
    "    plt.annotate(label,\n",
    "                 xy=(x, y),\n",
    "                 xytext=(5, 2),\n",
    "                 textcoords='offset points',\n",
    "                 ha='right',\n",
    "                 va='bottom')\n",
    "\n",
    "  plt.savefig(filename)\n",
    "\n",
    "try:\n",
    "  # pylint: disable=g-import-not-at-top\n",
    "  from sklearn.manifold import TSNE\n",
    "  import matplotlib.pyplot as plt\n",
    "  plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签\n",
    "  plt.rcParams['axes.unicode_minus']=False #用来正常显示负号\n",
    "  tsne = TSNE(perplexity=30, n_components=2, init='pca', n_iter=5000, method='exact')\n",
    "  plot_only = 500\n",
    "  low_dim_embs = tsne.fit_transform(final_embeddings[:plot_only, :])\n",
    "  labels = [reverse_dictionary[i] for i in xrange(plot_only)]\n",
    "  \n",
    "  plot_with_labels(low_dim_embs, labels, os.path.join(gettempdir(), 'tsne.png'))\n",
    "\n",
    "except ImportError as ex:\n",
    "  print('Please install sklearn, matplotlib, and scipy to show embeddings.')\n",
    "  print(ex)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# word2vec中，可以使用如下代码来保存最终生成的embeding\n",
    "np.save('embedding.npy', final_embeddings)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import json\n",
    "with open('vocabulary.json', 'w') as result_file:\n",
    "    json.dump(vocabulary, result_file)\n",
    "with open('dictionary.json', 'w') as result_file:\n",
    "    json.dump(dictionary, result_file)\n",
    "with open('reverse_dictionary.json', 'w') as result_file:\n",
    "    json.dump(reverse_dictionary, result_file)\n",
    "with open('data.json', 'w') as result_file:\n",
    "    json.dump(data, result_file)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
